#include <iostream>
#include <string>
using namespace std;

// 电脑主要组成部件 CPU , 显卡（videcard) 和 内存条（memory）
//每个零件都封装出抽象类 ， 并且提供不同厂商产不同的零件 ，如 Inrel 和 Lenovo
//电脑类提供电脑各组件工作的函数 ， 并且调用每个零件的接口
//组成三台电脑


//抽象零件类
class CPU {
public:
    //CPU 计算功能
    virtual void calculate() = 0;
    virtual ~CPU() {}
};
class VideCard{
public:
    //显卡显示功能
    virtual void display() = 0;
    virtual ~VideCard() {}
};
class Memory {
public:
    //内存条存储功能
    virtual void storage() = 0;
    virtual ~Memory() {}
};

//电脑类
class Computer {
private:
    CPU * cpu;
    VideCard * vc;
    Memory * mem;
public:
    Computer(CPU * cpu, VideCard * vc, Memory * mem) {
        this -> cpu =  cpu;
        this -> vc = vc;
        this -> mem = mem;
        cout << "电脑已组装完毕" << endl;
    }
    void Work() {
        cpu -> calculate();
        vc -> display();
        mem -> storage();
        cout << "电脑工作正常" << endl;
    }
    ~Computer() {
        if (cpu != nullptr) {
            delete cpu;
            cpu = nullptr;
        }
        if (vc != nullptr) {
            delete vc;
            vc = nullptr;
        }
        if (mem != nullptr) {
            delete mem;
            mem = nullptr;
        }
    }
};

//厂商类
// Intel
class IntelCPU : public CPU {
public:
    virtual void calculate() {
        cout << "使用intel的cpu正在工作" << endl;
    }
};
class IntelVideCard : public VideCard {
public:
    virtual void display() {
        cout << "使用intel的显卡正在工作" << endl;
    }
};
class IntelMemory : public Memory {
public:
    virtual void storage() {
        cout << "使用intel的内存条正在工作" << endl;
    }
};

// AMD
class AMDCPU : public CPU {
public:
     virtual void calculate() {
        cout << "使用AMD的cpu正在工作" << endl;
    }
};
class AMDVideCard : public VideCard {
public:
    virtual void display() {
        cout << "使用AMD的显卡正在工作" << endl;
    }
};
class AMDMemory : public Memory {
public:
    virtual void storage() {
        cout << "使用AMD的内存条正在工作" << endl;
    }
};
void test() {
    //组装第一台电脑
    CPU * cpu = new IntelCPU;
    VideCard * vc = new IntelVideCard;
    Memory * mem = new IntelMemory;

    Computer * com = new Computer(cpu, vc, mem);
    com -> Work();
    delete com;

    //组装第二台电脑
    cpu = new AMDCPU;
    vc = new AMDVideCard;
    mem = new AMDMemory;

    com = new Computer(cpu, vc, mem);
    com -> Work();
    delete com;

    //组装第三台电脑
    cpu = new IntelCPU;
    vc = new AMDVideCard;
    mem = new IntelMemory;
    com = new Computer(cpu, vc, mem);
    com -> Work();
    delete com;
}

int main() {
    test();
    return 0;
}